home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
qb4men.zip
/
MIKEBAR.BAS
Wrap
BASIC Source File
|
1987-12-26
|
11KB
|
311 lines
'Bounce-bar menu routine for Microsoft QuickBasic 4.0
'By Michael J. Himowitz, 8134 Scotts Level Rd, Baltimore, MD 21208
'CIS 71655,1327, Delphi MHIMOWITZ
'
'This set of routines will allow you to set up and call a series
'of Bounce-Bar type menus in QB4. The user may select a choice from
'a menu by moving the UP and DOWN cursor keys to highlight the choice
'and then hitting RETURN to make his selection. Or, he can just type
'the number opposite the choice. The user's choice (a number from 1 to 9)
'is returned to the program in a variable named CH. I've set up four menus
'in various colors (some pretty hideous) to demonstrate the program.
'You can monkey with the colors to your heart's content.
'
'The program makes use of two major routines. The first is a generic
'box drawing routine that can be used to draw a box on the screen anywhere.
'Here I used it to frame the entire screen for the menu. The second
'is the routine that creates the bounce-bar menu. I adapted it for the
'compiler from an interpreter routine by Frank R. Neal, whom I've never
'met but to whom I'm indebted for making me look like a much better
'programmer than I really am. The code here is fully commented. Just
'remember to set up your choices for each menu in the array M$() and tell
'the menu routine how many choices to display by assigning the number
'of choices to the variable NP. Hope you find this useful.
'
' I've also thrown in a demo of a routine that boxes text in any
' color. It's available from the first menu.
DECLARE SUB box (r1%, c1%, R2%, c2%, men%) ' Be sure to include these
DECLARE SUB rmsg (whichline!, tl$) ' lines at the top of your
DECLARE SUB menu (front, back, border) ' program. And of course, you
DIM SHARED m$(10), np, ch, yn$ ' must include the subroutines
DECLARE SUB yesorno () ' they reference.
DECLARE SUB center (whichline, tl$) '
DECLARE SUB box.text (msg$, row%, col%, front, back, ofront, oback)
DECLARE SUB hold ()
Second.title$ = "This is the Second Line of The Menu Title"
bottom.msg$ = "This is the bottom line of the Menu Screen"
'Note: the two variables above are for the second line of the menu title
'and the line that goes at the bottom of the menu screen.
'You can substitute anything you want here, or make them part of each
'menu routine as you call the menu.
7
'======= This starts the calling code for Menu No. 1 =======
first.menu:
m$(1) = "Go to Menu 2" 'These are the menu choices
m$(2) = "Go to Menu 3" 'that will be printed on the screen
m$(3) = "Go to Menu 4"
m$(5) = "Quit the Demo"
m$(4) = "Demo of Boxed Text"
np = 5 'This is the total number of choices
'You have a maximum of nine choices
COLOR 1, 7, 7 'This sets the overall screen colors
CLS
CALL box(1, 1, 24, 79, 1) 'Parameters are starting row, starting column,
'ending row and ending column. The last parameter,
'set to 1, puts bars at the top and bottom of the
'box to set off the title and bottom line of a
'menu screen. If you set the last parameter to
'zero, you'll just get a box.
CALL center(2, "This is the First Menu Title") 'Prints the first menu title
CALL center(3, Second.title$) 'Prints the second menu title
CALL center(23, bottom.msg$) 'Bottom line message
menu 4, 7, 7 'The parameters are the foreground, background
'and border colors for the menu printing
CLS
ON ch GOTO second.menu, third.menu, fourth.menu, box.demo, quittin.time
'======= This is the end of the first menu call ===========
'======= The value of the menu choice is returned in variable CH ======
second.menu:
m$(1) = "Go to First Menu"
m$(2) = "Go to Third Menu"
m$(3) = "Go to the Fourth Menu"
m$(4) = "Quit The Demo"
np = 4
COLOR 7, 0, 0
CLS
CALL box(1, 1, 24, 79, 1)
CALL center(2, "This is Menu No. 2")
CALL center(3, Second.title$)
CALL center(23, bottom.msg$)
CALL menu(14, 0, 0)
ON ch GOTO first.menu, third.menu, fourth.menu, quittin.time
third.menu:
m$(1) = "Go to First Menu"
m$(2) = "Go to Second Menu"
m$(3) = "Go to the Fourth Menu"
m$(4) = "Quit The Demo"
np = 4
COLOR 7, 4, 4
CLS
CALL box(1, 1, 24, 79, 1)
CALL center(2, "This is Menu No. 3")
CALL center(3, Second.title$)
CALL center(23, bottom.msg$)
CALL menu(0, 4, 4)
ON ch GOTO first.menu, second.menu, fourth.menu, quittin.time
fourth.menu:
m$(1) = "Go to First Menu"
m$(2) = "Go to Second Menu"
m$(3) = "Go to the Third Menu"
m$(4) = "Quit The Demo"
np = 4
COLOR 7, 1, 1
CLS
CALL box(1, 1, 24, 79, 1)
CALL center(2, "This is Menu No. 4")
CALL center(3, Second.title$)
CALL center(23, bottom.msg$)
CALL menu(6, 1, 1)
ON ch GOTO first.menu, second.menu, third.menu, quittin.time
quittin.time:
COLOR 7, 0, 0: CLS
SOUND 1200, 2
CALL rmsg(10, "Do you want to Quit? (Y/N)")
yesorno
IF yn$ <> "Y" THEN GOTO first.menu
END
box.demo: 'This is a demo of how to box text
COLOR 7, 0, 0 'in any color. For explanation, see the
CLS 'remarks in the box.text subprogram
box.text "This is some text", 3, 8, 7, 1, 7, 0
box.text "Here's some more text", 7, 15, 4, 1, 7, 0
box.text "And another piece of text", 22, 40, 1, 6, 7, 0
box.text "Here's some more stuff", 12, 33, 15, 13, 7, 0
box.text "Now is the time for all good men", 19, 16, 2, 0, 7, 0
SOUND 1200, 2
COLOR 7, 0
center 25, "Strike the space bar repeatedly to make the boxes disappear."
'The following routines erase the boxes one by one.
hold
box.text "Now is the time for all good men", 19, 16, 0, 0, 7, 0
hold
box.text "Here's some more stuff", 12, 33, 0, 0, 7, 0
hold
box.text "And another piece of text", 22, 40, 0, 0, 7, 0
hold
box.text "Here's some more text", 7, 15, 0, 0, 7, 0
hold
box.text "This is some text", 3, 8, 0, 0, 7, 0
CLS
GOTO first.menu
END
SUB box (r1%, c1%, R2%, c2%, men%)
' DRAW A BOX AT SPECIFIED COORDINATE
' This is a generic routine that can be used to draw a box anywhere.
' r1% is the starting row. c1% is the starting column.
' r2% is the ending row. c2% is the ending column.
' The paramater men%, set to 1, prints horizontal bars
' three rows down from the top of the box and two rows up from the bottom.
' If men% is set to 0, the routine will print a plain box.
GLOOP$ = "║"
BOXTOP = (c2% - c1%) - 1: BOXTOP$ = CHR$(201) + STRING$(BOXTOP, 205) + CHR$(187): BOXBOTTOM$ = CHR$(200) + STRING$(BOXTOP, 205) + CHR$(188)
MIDBOX$ = CHR$(204) + STRING$(BOXTOP, 205) + CHR$(185)
LOCATE r1%, c1%: PRINT BOXTOP$; : FOR E1% = r1% + 1 TO R2% - 1: LOCATE E1%, c1%: PRINT GLOOP$; : LOCATE E1%, c2%: PRINT GLOOP$; : NEXT
LOCATE R2%, c1%: PRINT BOXBOTTOM$;
IF men% > 0 THEN 'Prints optional top and bottom bars in box
LOCATE r1% + 3, c1%: PRINT MIDBOX$;
LOCATE R2% - 2, c1%: PRINT MIDBOX$;
END IF
END SUB
SUB box.text (tl$, r1%, c1%, fgd, bkg, ofg, obk)
' BOX TEXT AT SPECIFIED COORDINATE
'This routine will box a one-line string of text in the color
'of your choice at the starting coordinate you choose.
'TL$ is the text, r1% is the starting row, c1% is the starting column.
'fgd and bkg are the fore and background colors of the boxed text.
'ofg and obk are the colors to restore after you've boxed the text.
GLOOP$ = "║"
BOXTOP = LEN(tl$) + 2
BOXTOP$ = CHR$(201) + STRING$(BOXTOP, 205) + CHR$(187): BOXBOTTOM$ = CHR$(200) + STRING$(BOXTOP, 205) + CHR$(188)
MIDBOX$ = GLOOP$ + " " + tl$ + " " + GLOOP$
COLOR fgd, bkg
LOCATE r1%, c1%: PRINT BOXTOP$; : E1% = r1% + 1: R2% = E1% + 1
LOCATE E1%, c1%: PRINT MIDBOX$;
LOCATE R2%, c1%: PRINT BOXBOTTOM$;
COLOR ofg, obk 'switch to these text colors after boxing the text
END SUB
SUB center (whichline, tl$)
'This is a simple routine that centers a string of text TL$
'on line number WHICHLINE. You can use it anywhere.
tl = LEN(tl$)
tl = INT((80 - tl) / 2)
LOCATE which